# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: C. Dominik Bódi <dominik dot bodi at gmx dot de>

pkgname=signing-party
pkgver=2.11
pkgrel=1
pkgdesc="Collection for all kinds of pgp related things, including signing scripts, party preparation scripts, etc."
arch=(loong64 x86_64)
url="https://salsa.debian.org/signing-party-team/signing-party"
license=(GPL)
depends=(libmd
         perl-class-methodmaker
         perl-gnupg-interface
         perl-mailtools
         perl-mime-tools
         perl-net-idn-encode 
         perl-term-readkey
         perl-text-template
         qprint)
optdepends=('python: keyart support'
            'imagemagick: photo uid support in gpgsigs'
            'perl-gd: springgraph support'
            'qrencode: QR code support in gpg-key2latex'
            'texlive-latexextra: QR code support in gpg-key2latex'
            'noto-fonts: fonts for pretty printouts'
            'noto-fonts-cjk: fonts for pretty printouts')
source=("${url}/-/archive/v${pkgver}/${pkgname}-v${pkgver}.tar.bz2"
        'gpgwrap_makefile.patch')
sha256sums=('7413024a84546d7aa61175874e7158daa02dac085b64540d7283f9e0161b6a7c'
            '1a5b7ec8dca7642b744270ab5011707f9f4b732cba8062c76b5195c40f13f5e0')

prepare() {
    cd ${pkgname}-v${pkgver}
    # Remove useless buggy Makefile
    rm gpgwrap/src/Makefile
    patch -p1 -i ../gpgwrap_makefile.patch
}

build() {
    cd ${pkgname}-v${pkgver}
    make
}

package() {
    cd ${pkgname}-v${pkgver}
    make DESTDIR="${pkgdir}" install

    # Manually install all files the Makefiles in the subpackages are not installing
    # TODO: Fix this upstream instead

    install -Dm644 README -t "${pkgdir}"/usr/share/doc/signing-party/

    for project in caff gpgdir gpg-key2latex gpg-key2ps gpglist gpg-mailkeys gpgparticipants gpgsigs ; do
        install -Dm755 ${project}/${project} -t "${pkgdir}"/usr/bin/
        install -Dm644 ${project}/${project}.1 -t "${pkgdir}"/usr/share/man/man1/
    done

    install -Dm755 caff/{pgp-clean,pgp-fixkey} -t "${pkgdir}"/usr/bin/
    install -Dm644 caff/{pgp-clean,pgp-fixkey}.1 -t "${pkgdir}"/usr/share/man/man1/
    install -Dm644 caff/{caffrc.sample,README*} -t "${pkgdir}"/usr/share/doc/signing-party/caff/

    install -Dm644 gpg-key2ps/README -t "${pkgdir}"/usr/share/doc/signing-party/gpg-key2ps/

    install -Dm755 gpgparticipants/gpgparticipants-prefill -t "${pkgdir}"/usr/bin/
    install -Dm644 gpgparticipants/gpgparticipants-prefill.1 -t "${pkgdir}"/usr/share/man/man1/

    install -Dm644 gpgsigs/gpgsigs-lt2k5{,-annotated}.txt -t "${pkgdir}"/usr/share/doc/signing-party/examples/gpgsigs/

    install -Dm755 gpgwrap/src/gpgwrap -t "${pkgdir}"/usr/bin/
    install -Dm644 gpgwrap/doc/gpgwrap.1 -t "${pkgdir}"/usr/share/man/man1/

    install -Dm644 keyanalyze/{keyanalyze,process_keys,pgpring/pgpring}.1 -t "${pkgdir}"/usr/share/man/man1/
    install -Dm755 keyanalyze/{allkeys,analyze}.sh -t "${pkgdir}"/usr/share/doc/signing-party/examples/keyanalyze/
    install -Dm644 keyanalyze/README -t "${pkgdir}"/usr/share/doc/signing-party/examples/keyanalyze/

    install -Dm755 keyanalyze/scripts/* -t "${pkgdir}"/usr/share/doc/signing-party/examples/keyanalyze/scripts/
    chmod 644 "${pkgdir}"/usr/share/doc/signing-party/examples/keyanalyze/scripts/top50comments.txt
    install -Dm755 keyanalyze/willy/* -t "${pkgdir}"/usr/share/doc/signing-party/examples/keyanalyze/willy/
    chmod 644 "${pkgdir}"/usr/share/doc/signing-party/examples/keyanalyze/willy/README

    install -Dm755 keyart/keyart -t "${pkgdir}"/usr/bin/
    install -Dm644 keyart/doc/keyart.1 -t "${pkgdir}"/usr/share/man/man1/
    install -Dm644 keyart/{README,doc/{druken-bishop.txt,party-worksheet}} -t "${pkgdir}"/usr/share/doc/signing-party/keyart/
    install -Dm755 keyart/doc/examples/party.sh -t "${pkgdir}"/usr/share/doc/signing-party/examples/keyart/
}
